package com.jcli.novel_p;

import java.io.*;
import java.util.*;

public class AddRandomProperties01 {
    public static void main(String[] args) {
        // 新建一个 Properties 对象
        Properties properties = new Properties();

        // 生成并添加 100 个随机键值对
        for (int i = 0; i < 100; i++) {
            String key = "Key" + i;
            String value = generateRandomValue();
            properties.setProperty(key, value);
        }

        try (OutputStream outputStream = new FileOutputStream("src/main/resources/config.properties")) {
            properties.store(outputStream, null);
            System.out.println("成功添加 100 个随机键值对到 config.properties 文件。");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static String generateRandomValue() {
        // 生成一个随机整数作为值
        Random random = new Random();
        int randomValue = random.nextInt(1000);
        return String.valueOf(randomValue);
    }
}
